package cn.hd.service.impl;

import cn.hd.dao.LicenseDao;
import cn.hd.dao.ReallynameDao;
import cn.hd.entity.AuthRealName;
import cn.hd.entity.License;
import cn.hd.entity.Reallyname;
import cn.hd.entity.User;
import cn.hd.service.ReallynameService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ReallynameImpl implements ReallynameService {
    @Autowired
    private ReallynameDao reallynameDao;
    @Autowired
    private LicenseDao licenseDao;

    @Override
    public int addReallyname(Reallyname reallyname) {
        int i = reallynameDao.addReallyname(reallyname);
        return i;
    }

    @Override
    public int passAuthRealName(long authrealid) {
        return reallynameDao.passAuthRealName(authrealid);
    }

    @Override
    public Reallyname selectByUserIdRealname(long userid){
        Reallyname reallyname = null;
        try {
            reallyname = reallynameDao.selectByUserIdRealname(userid);
            if (reallyname!=null){
                String s = reallyname.getPicture().substring(0, reallyname.getPicture().length());
                String[] split = s.split(",");
                reallyname.setPic(split);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return reallyname;
    }

    @Override
    public int failAuthRealName(long authrealid) {
        return reallynameDao.failAuthRealName(authrealid);
    }

    @Override
    public PageInfo<AuthRealName> selectAuthRealName(int pagenum, Map map, int pagesize){
        PageHelper.startPage(pagenum, pagesize);
        PageInfo<AuthRealName> page= null;
        try {
            List<AuthRealName> authRealNames = reallynameDao.selectAuthRealName(map);
            page = new PageInfo<>(authRealNames);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return page;
    }

    @Override
    public AuthRealName selectByIdAuthRealName(long authrealid){
        return reallynameDao.selectByIdAuthRealName(authrealid);
    }

    //修改角色
    @Override
    public int updaterole(long id){
        return reallynameDao.updaterole(id);
    }

    //根据真是i姓名查询id
    @Override
    public Reallyname selectByUname(String uname){
        Reallyname reallyname = reallynameDao.selectByUname(uname);
        License license = licenseDao.selectLicenseByLicenseId(reallyname.getType());
        reallyname.setLicense_name(license.getLicense_name());
        String s = reallyname.getPicture().substring(0, reallyname.getPicture().length());
        String[] split = s.split(",");
        reallyname.setPic(split);
        return reallyname;
    }


}
